package com.kingyea.app.market.user.service.impl;

import com.kingyea.app.market.user.dao.UserMapper;
import com.kingyea.app.market.user.service.UserService;
import com.kingyea.app.market.utils.page.PageInfo;
import com.kingyea.mobilepolice.user.bean.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author
 * @version v1.0.0
 * @description User 实现类
 * @date Created in 2018-02-09 17:37:33
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserServiceImpl.class);

    @Resource
    private UserMapper userMapper;

    /**
     * 通过ID查找对象
     *
     * @return
     */
    @Override
    public User getById(String id) throws Exception {
        return this.userMapper.getById(id);
    }

    /**
     * 列表
     *
     * @param
     * @return
     */
    @Override
    public Object list(Map<String, Object> user) throws Exception {
        PageInfo.startPage(user);
        return PageInfo.getPageInfo(userMapper.list(user));
    }

    /**
     * 删除
     *
     * @return
     */
    @Override
    public int deleteById(User user) throws Exception {
        userMapper.deleteById(user);
        return 1;
    }

    /**
     * 保存
     *
     * @param user
     * @return
     */
    @Override
    public User save(User user) throws Exception {
        try {
            userMapper.save(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return user;
    }

    /**
     * 更新
     *
     * @param user
     * @return
     */
    @Override
    public User update(User user) throws Exception {
        try {
            userMapper.update(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return user;
    }

    @Override
    public Object getListBySupplier(Map<String, Object> obj) throws Exception {
        PageInfo.startPage(obj);
        return PageInfo.getPageInfo(userMapper.getListBySupplier(obj));
    }


}
